home *** CD-ROM | disk | FTP | other *** search
/ Nebula 1 / Nebula One.iso / Misc / BMV / Source / TopControl.m < prev   
Encoding:
Text File  |  1995-06-12  |  3.6 KB  |  160 lines

  1. #import "TopControl.h"
  2. #import "ScaledView.h"
  3.  
  4. #import <dpsclient/dpsclient.h>
  5. #import <appkit/Application.h>
  6. #import <appkit/Window.h>
  7. #import <appkit/graphics.h>
  8. #import <appkit/NXBitmapImageRep.h>
  9. #import <appkit/OpenPanel.h>
  10.  
  11. @implementation TopControl
  12. - appDidInit:sender
  13. {
  14.   NXRect frame;
  15.   [[window contentView] getFrame:&frame];
  16.   frame.origin.x=0.0;
  17.   frame.origin.y=0.0;
  18.  
  19.   // currently hardwired to ScaledView.  Simply add whatever
  20.   // view you want to the project and grab a new instance here.  Everything
  21.   // should work just dandy after that.
  22.   view1=[[ScaledView alloc] initFrame:&frame];
  23.   [view1 setAutosizing:NX_WIDTHSIZABLE | NX_HEIGHTSIZABLE];
  24.   [[window contentView] addSubview:view1];
  25.   [window useOptimizedDrawing:YES];
  26.   [window setBackgroundGray:NX_BLACK];
  27.   return self;
  28. }
  29.  
  30. - doIE
  31. {
  32.   NXEvent dummyEvent, *evnt;
  33.  
  34.   [infoView lockFocus];
  35.   do {
  36.     [infoView oneStep];
  37.     [infoView oneStep]; // do two steps
  38.  
  39.     evnt=[NXApp peekNextEvent:NX_ALLEVENTS into:&dummyEvent waitFor:0
  40.       threshold:NX_BASETHRESHOLD];
  41.   } while(infoRun && !evnt);
  42.     
  43.   [infoView unlockFocus];
  44.   return self;
  45. }  
  46.  
  47. void itehandler(DPSTimedEntry te, double time, void *tobj)
  48. { [(id)tobj doIE]; }
  49.  
  50. - infoPanel:sender
  51. {
  52.   [infoPanel makeKeyAndOrderFront:self];
  53.   if(!infoRun){
  54.     ientry=DPSAddTimedEntry(0.02, &itehandler, self, NX_BASETHRESHOLD);
  55.     infoRun=YES;
  56.   }
  57.   return self;
  58. }
  59.  
  60. - windowWillClose:sender
  61. {
  62.   if (sender==infoPanel) {
  63.     infoRun=NO;
  64.     DPSRemoveTimedEntry(ientry);
  65.   }
  66.   return self;
  67. }
  68.  
  69. - doTE
  70. {
  71.   NXEvent dummyEvent, *evnt;
  72.   NXEvent *theEvent, nextEvent;
  73.   char bname[50], name[100];
  74.   NXBitmapImageRep *theRep;
  75.   NXStream *theStream;
  76.   NXRect theRect;
  77.   int count=0;
  78.   BOOL advancedCommandSet=[view1 advancedCommandSet];
  79.   
  80.   sprintf(bname,"/tmp/%s", [view1 name]);
  81.   
  82.   [view1 lockFocus];
  83.   do {
  84.     [view1 oneStep];
  85.     [view1 oneStep]; // do two steps
  86.  
  87.     // this if statement basically does some advanced sort of stuff if the
  88.     // view supports it.  It currently isn''t documented, but will be in the
  89.     // future. Check out FooFaraw.m and ScaledView.m for a view that supports
  90.     // such goofiness...
  91.     if(advancedCommandSet &&
  92.        [NXApp peekNextEvent:NX_FLAGSCHANGEDMASK
  93.     into:&nextEvent]){
  94.       theEvent=[NXApp getNextEvent:NX_FLAGSCHANGEDMASK];
  95.       if(theEvent->flags & NX_COMMANDMASK) {
  96.     if([view1
  97.         respondsTo:@selector(commandKey)]){
  98.       [view1 commandKey];
  99.     }
  100.       } else
  101.     if(theEvent->flags & NX_ALTERNATEMASK) {
  102.       [view1 getBounds:&theRect];
  103.       theRep = [[NXBitmapImageRep alloc]
  104.             initData:NULL fromRect:&theRect];
  105.       sprintf(name, "%s.%d.tiff", bname, count++);
  106.       fprintf(stdout, "BackSpace (%s) Saving: %s\n",
  107.           [view1 name], name);
  108.       theStream=NXOpenMemory(NULL, 0, NX_WRITEONLY);
  109.       if(theStream) {
  110.         [theRep writeTIFF:theStream];
  111.         if(NXSaveToFile(theStream, name) != 0) {
  112.           fprintf(stderr, "FooFaraw:save failed!\n");
  113.         }
  114.         NXClose(theStream);
  115.       } else {
  116.         fprintf(stderr,
  117.             "FooFaraw: could not save!\n");
  118.       }
  119.       [theRep free];
  120.     }
  121.     }
  122.     evnt=[NXApp peekNextEvent:NX_ALLEVENTS into:&dummyEvent waitFor:0
  123.       threshold:NX_BASETHRESHOLD];
  124.   } while(running && !evnt);
  125.     
  126.   [view1 unlockFocus];
  127.   return self;
  128. }
  129.  
  130. void tehandler(DPSTimedEntry te, double time, void *tobj)
  131. { [(id)tobj doTE]; }
  132.  
  133. - runStop:sender
  134. {
  135.   if(!running){
  136.     // add the timed entry
  137.     tentry=DPSAddTimedEntry(0.02, &tehandler, self, NX_BASETHRESHOLD);
  138.     running=YES;
  139.   } else {
  140.     running=NO;
  141.     DPSRemoveTimedEntry(tentry);
  142.   }
  143.   return self;
  144.   
  145. /*   [view1 lockFocus];
  146.   for(i=0;i<1000;i++)
  147.     [view1 oneStep]; 
  148.   
  149.   [view1 unlockFocus];
  150.   */
  151. }
  152.  
  153. - open:sender
  154. {
  155.     return self;
  156. }
  157.  
  158.  
  159. @end
  160.